package com.binfast.codegen.gen;

import com.binfast.codegen.gen.genTarget.Target;
import com.binfast.codegen.gen.model.Entity;
import org.beetl.core.GroupTemplate;
import org.beetl.core.Template;

public class JSGen  implements AutoGen {

	@Override
	public void make(Target target, Entity entity) {
		JSApiGen apiGen = new JSApiGen();
		apiGen.make(target, entity);
	}
	@Override
	public String getName() {
		return "";
	}
	
}

class JSApiGen  implements AutoGen {
	
	Entity entity;
	@Override
	public void make(Target target, Entity entity) {
		this.entity =entity;
		GroupTemplate gt = target.getGroupTemplate();
		Template template = gt.getTemplate("/js/api.js");
		template.binding("entity", entity);
		template.binding("target", target);
		String content = template.render();
		target.flush(this, content);
		
	}
	@Override
	public String getName() {
		return entity.getCode()+".js";
	}
	
}





